<?php

/**
 * Base class that represents a row from the 'Users' table.
 *
 * 
 *
 * @package    .om
 */
abstract class BaseUsers extends BaseObject  implements Persistent {


	/**
	 * The Peer class.
	 * Instance provides a convenient way of calling static methods on a class
	 * that calling code may not be able to identify.
	 * @var        UsersPeer
	 */
	protected static $peer;

	/**
	 * The value for the id_user field.
	 * @var        int
	 */
	protected $id_user;

	/**
	 * The value for the login field.
	 * @var        string
	 */
	protected $login;

	/**
	 * The value for the password field.
	 * @var        string
	 */
	protected $password;

	/**
	 * The value for the avatar field.
	 * @var        string
	 */
	protected $avatar;

	/**
	 * The value for the email field.
	 * @var        string
	 */
	protected $email;

	/**
	 * The value for the birthdate field.
	 * @var        string
	 */
	protected $birthdate;

	/**
	 * The value for the registerdate field.
	 * @var        string
	 */
	protected $registerdate;

	/**
	 * The value for the lastlogindate field.
	 * @var        string
	 */
	protected $lastlogindate;

	/**
	 * The value for the clickcounter field.
	 * Note: this column has a database default value of: 0
	 * @var        int
	 */
	protected $clickcounter;

	/**
	 * The value for the ratingcounter field.
	 * Note: this column has a database default value of: 0
	 * @var        int
	 */
	protected $ratingcounter;

	/**
	 * The value for the id_users_permission field.
	 * @var        int
	 */
	protected $id_users_permission;

	/**
	 * The value for the id_preferences_group field.
	 * @var        int
	 */
	protected $id_preferences_group;

	/**
	 * @var        Userspermissions
	 */
	protected $aUserspermissions;

	/**
	 * @var        Preferencesgroups
	 */
	protected $aPreferencesgroups;

	/**
	 * @var        array News[] Collection to store aggregation of News objects.
	 */
	protected $collNewss;

	/**
	 * @var        Criteria The criteria used to select the current contents of collNewss.
	 */
	private $lastNewsCriteria = null;

	/**
	 * @var        Newsratingstatistics one-to-one related Newsratingstatistics object
	 */
	protected $singleNewsratingstatistics;

	/**
	 * @var        array Reviewrequests[] Collection to store aggregation of Reviewrequests objects.
	 */
	protected $collReviewrequestss;

	/**
	 * @var        Criteria The criteria used to select the current contents of collReviewrequestss.
	 */
	private $lastReviewrequestsCriteria = null;

	/**
	 * @var        array Userscategoriesclicks[] Collection to store aggregation of Userscategoriesclicks objects.
	 */
	protected $collUserscategoriesclickss;

	/**
	 * @var        Criteria The criteria used to select the current contents of collUserscategoriesclickss.
	 */
	private $lastUserscategoriesclicksCriteria = null;

	/**
	 * Flag to prevent endless save loop, if this object is referenced
	 * by another object which falls in this transaction.
	 * @var        boolean
	 */
	protected $alreadyInSave = false;

	/**
	 * Flag to prevent endless validation loop, if this object is referenced
	 * by another object which falls in this transaction.
	 * @var        boolean
	 */
	protected $alreadyInValidation = false;

	/**
	 * Initializes internal state of BaseUsers object.
	 * @see        applyDefaults()
	 */
	public function __construct()
	{
		parent::__construct();
		$this->applyDefaultValues();
	}

	/**
	 * Applies default values to this object.
	 * This method should be called from the object's constructor (or
	 * equivalent initialization method).
	 * @see        __construct()
	 */
	public function applyDefaultValues()
	{
		$this->clickcounter = 0;
		$this->ratingcounter = 0;
	}

	/**
	 * Get the [id_user] column value.
	 * 
	 * @return     int
	 */
	public function getIdUser()
	{
		return $this->id_user;
	}

	/**
	 * Get the [login] column value.
	 * 
	 * @return     string
	 */
	public function getLogin()
	{
		return $this->login;
	}

	/**
	 * Get the [password] column value.
	 * 
	 * @return     string
	 */
	public function getPassword()
	{
		return $this->password;
	}

	/**
	 * Get the [avatar] column value.
	 * 
	 * @return     string
	 */
	public function getAvatar()
	{
		return $this->avatar;
	}

	/**
	 * Get the [email] column value.
	 * 
	 * @return     string
	 */
	public function getEmail()
	{
		return $this->email;
	}

	/**
	 * Get the [optionally formatted] temporal [birthdate] column value.
	 * 
	 *
	 * @param      string $format The date/time format string (either date()-style or strftime()-style).
	 *							If format is NULL, then the raw DateTime object will be returned.
	 * @return     mixed Formatted date/time value as string or DateTime object (if format is NULL), NULL if column is NULL, and 0 if column value is 0000-00-00
	 * @throws     PropelException - if unable to parse/validate the date/time value.
	 */
	public function getBirthdate($format = '%x')
	{
		if ($this->birthdate === null) {
			return null;
		}


		if ($this->birthdate === '0000-00-00') {
			// while technically this is not a default value of NULL,
			// this seems to be closest in meaning.
			return null;
		} else {
			try {
				$dt = new DateTime($this->birthdate);
			} catch (Exception $x) {
				throw new PropelException("Internally stored date/time/timestamp value could not be converted to DateTime: " . var_export($this->birthdate, true), $x);
			}
		}

		if ($format === null) {
			// Because propel.useDateTimeClass is TRUE, we return a DateTime object.
			return $dt;
		} elseif (strpos($format, '%') !== false) {
			return strftime($format, $dt->format('U'));
		} else {
			return $dt->format($format);
		}
	}

	/**
	 * Get the [optionally formatted] temporal [registerdate] column value.
	 * 
	 *
	 * @param      string $format The date/time format string (either date()-style or strftime()-style).
	 *							If format is NULL, then the raw DateTime object will be returned.
	 * @return     mixed Formatted date/time value as string or DateTime object (if format is NULL), NULL if column is NULL, and 0 if column value is 0000-00-00
	 * @throws     PropelException - if unable to parse/validate the date/time value.
	 */
	public function getRegisterdate($format = '%x')
	{
		if ($this->registerdate === null) {
			return null;
		}


		if ($this->registerdate === '0000-00-00') {
			// while technically this is not a default value of NULL,
			// this seems to be closest in meaning.
			return null;
		} else {
			try {
				$dt = new DateTime($this->registerdate);
			} catch (Exception $x) {
				throw new PropelException("Internally stored date/time/timestamp value could not be converted to DateTime: " . var_export($this->registerdate, true), $x);
			}
		}

		if ($format === null) {
			// Because propel.useDateTimeClass is TRUE, we return a DateTime object.
			return $dt;
		} elseif (strpos($format, '%') !== false) {
			return strftime($format, $dt->format('U'));
		} else {
			return $dt->format($format);
		}
	}

	/**
	 * Get the [optionally formatted] temporal [lastlogindate] column value.
	 * 
	 *
	 * @param      string $format The date/time format string (either date()-style or strftime()-style).
	 *							If format is NULL, then the raw DateTime object will be returned.
	 * @return     mixed Formatted date/time value as string or DateTime object (if format is NULL), NULL if column is NULL, and 0 if column value is 0000-00-00 00:00:00
	 * @throws     PropelException - if unable to parse/validate the date/time value.
	 */
	public function getLastlogindate($format = 'Y-m-d H:i:s')
	{
		if ($this->lastlogindate === null) {
			return null;
		}


		if ($this->lastlogindate === '0000-00-00 00:00:00') {
			// while technically this is not a default value of NULL,
			// this seems to be closest in meaning.
			return null;
		} else {
			try {
				$dt = new DateTime($this->lastlogindate);
			} catch (Exception $x) {
				throw new PropelException("Internally stored date/time/timestamp value could not be converted to DateTime: " . var_export($this->lastlogindate, true), $x);
			}
		}

		if ($format === null) {
			// Because propel.useDateTimeClass is TRUE, we return a DateTime object.
			return $dt;
		} elseif (strpos($format, '%') !== false) {
			return strftime($format, $dt->format('U'));
		} else {
			return $dt->format($format);
		}
	}

	/**
	 * Get the [clickcounter] column value.
	 * 
	 * @return     int
	 */
	public function getClickcounter()
	{
		return $this->clickcounter;
	}

	/**
	 * Get the [ratingcounter] column value.
	 * 
	 * @return     int
	 */
	public function getRatingcounter()
	{
		return $this->ratingcounter;
	}

	/**
	 * Get the [id_users_permission] column value.
	 * 
	 * @return     int
	 */
	public function getIdUsersPermission()
	{
		return $this->id_users_permission;
	}

	/**
	 * Get the [id_preferences_group] column value.
	 * 
	 * @return     int
	 */
	public function getIdPreferencesGroup()
	{
		return $this->id_preferences_group;
	}

	/**
	 * Set the value of [id_user] column.
	 * 
	 * @param      int $v new value
	 * @return     Users The current object (for fluent API support)
	 */
	public function setIdUser($v)
	{
		if ($v !== null) {
			$v = (int) $v;
		}

		if ($this->id_user !== $v) {
			$this->id_user = $v;
			$this->modifiedColumns[] = UsersPeer::ID_USER;
		}

		return $this;
	} // setIdUser()

	/**
	 * Set the value of [login] column.
	 * 
	 * @param      string $v new value
	 * @return     Users The current object (for fluent API support)
	 */
	public function setLogin($v)
	{
		if ($v !== null) {
			$v = (string) $v;
		}

		if ($this->login !== $v) {
			$this->login = $v;
			$this->modifiedColumns[] = UsersPeer::LOGIN;
		}

		return $this;
	} // setLogin()

	/**
	 * Set the value of [password] column.
	 * 
	 * @param      string $v new value
	 * @return     Users The current object (for fluent API support)
	 */
	public function setPassword($v)
	{
		if ($v !== null) {
			$v = (string) $v;
		}

		if ($this->password !== $v) {
			$this->password = $v;
			$this->modifiedColumns[] = UsersPeer::PASSWORD;
		}

		return $this;
	} // setPassword()

	/**
	 * Set the value of [avatar] column.
	 * 
	 * @param      string $v new value
	 * @return     Users The current object (for fluent API support)
	 */
	public function setAvatar($v)
	{
		if ($v !== null) {
			$v = (string) $v;
		}

		if ($this->avatar !== $v) {
			$this->avatar = $v;
			$this->modifiedColumns[] = UsersPeer::AVATAR;
		}

		return $this;
	} // setAvatar()

	/**
	 * Set the value of [email] column.
	 * 
	 * @param      string $v new value
	 * @return     Users The current object (for fluent API support)
	 */
	public function setEmail($v)
	{
		if ($v !== null) {
			$v = (string) $v;
		}

		if ($this->email !== $v) {
			$this->email = $v;
			$this->modifiedColumns[] = UsersPeer::EMAIL;
		}

		return $this;
	} // setEmail()

	/**
	 * Sets the value of [birthdate] column to a normalized version of the date/time value specified.
	 * 
	 * @param      mixed $v string, integer (timestamp), or DateTime value.  Empty string will
	 *						be treated as NULL for temporal objects.
	 * @return     Users The current object (for fluent API support)
	 */
	public function setBirthdate($v)
	{
		// we treat '' as NULL for temporal objects because DateTime('') == DateTime('now')
		// -- which is unexpected, to say the least.
		if ($v === null || $v === '') {
			$dt = null;
		} elseif ($v instanceof DateTime) {
			$dt = $v;
		} else {
			// some string/numeric value passed; we normalize that so that we can
			// validate it.
			try {
				if (is_numeric($v)) { // if it's a unix timestamp
					$dt = new DateTime('@'.$v, new DateTimeZone('UTC'));
					// We have to explicitly specify and then change the time zone because of a
					// DateTime bug: http://bugs.php.net/bug.php?id=43003
					$dt->setTimeZone(new DateTimeZone(date_default_timezone_get()));
				} else {
					$dt = new DateTime($v);
				}
			} catch (Exception $x) {
				throw new PropelException('Error parsing date/time value: ' . var_export($v, true), $x);
			}
		}

		if ( $this->birthdate !== null || $dt !== null ) {
			// (nested ifs are a little easier to read in this case)

			$currNorm = ($this->birthdate !== null && $tmpDt = new DateTime($this->birthdate)) ? $tmpDt->format('Y-m-d') : null;
			$newNorm = ($dt !== null) ? $dt->format('Y-m-d') : null;

			if ( ($currNorm !== $newNorm) // normalized values don't match 
					)
			{
				$this->birthdate = ($dt ? $dt->format('Y-m-d') : null);
				$this->modifiedColumns[] = UsersPeer::BIRTHDATE;
			}
		} // if either are not null

		return $this;
	} // setBirthdate()

	/**
	 * Sets the value of [registerdate] column to a normalized version of the date/time value specified.
	 * 
	 * @param      mixed $v string, integer (timestamp), or DateTime value.  Empty string will
	 *						be treated as NULL for temporal objects.
	 * @return     Users The current object (for fluent API support)
	 */
	public function setRegisterdate($v)
	{
		// we treat '' as NULL for temporal objects because DateTime('') == DateTime('now')
		// -- which is unexpected, to say the least.
		if ($v === null || $v === '') {
			$dt = null;
		} elseif ($v instanceof DateTime) {
			$dt = $v;
		} else {
			// some string/numeric value passed; we normalize that so that we can
			// validate it.
			try {
				if (is_numeric($v)) { // if it's a unix timestamp
					$dt = new DateTime('@'.$v, new DateTimeZone('UTC'));
					// We have to explicitly specify and then change the time zone because of a
					// DateTime bug: http://bugs.php.net/bug.php?id=43003
					$dt->setTimeZone(new DateTimeZone(date_default_timezone_get()));
				} else {
					$dt = new DateTime($v);
				}
			} catch (Exception $x) {
				throw new PropelException('Error parsing date/time value: ' . var_export($v, true), $x);
			}
		}

		if ( $this->registerdate !== null || $dt !== null ) {
			// (nested ifs are a little easier to read in this case)

			$currNorm = ($this->registerdate !== null && $tmpDt = new DateTime($this->registerdate)) ? $tmpDt->format('Y-m-d') : null;
			$newNorm = ($dt !== null) ? $dt->format('Y-m-d') : null;

			if ( ($currNorm !== $newNorm) // normalized values don't match 
					)
			{
				$this->registerdate = ($dt ? $dt->format('Y-m-d') : null);
				$this->modifiedColumns[] = UsersPeer::REGISTERDATE;
			}
		} // if either are not null

		return $this;
	} // setRegisterdate()

	/**
	 * Sets the value of [lastlogindate] column to a normalized version of the date/time value specified.
	 * 
	 * @param      mixed $v string, integer (timestamp), or DateTime value.  Empty string will
	 *						be treated as NULL for temporal objects.
	 * @return     Users The current object (for fluent API support)
	 */
	public function setLastlogindate($v)
	{
		// we treat '' as NULL for temporal objects because DateTime('') == DateTime('now')
		// -- which is unexpected, to say the least.
		if ($v === null || $v === '') {
			$dt = null;
		} elseif ($v instanceof DateTime) {
			$dt = $v;
		} else {
			// some string/numeric value passed; we normalize that so that we can
			// validate it.
			try {
				if (is_numeric($v)) { // if it's a unix timestamp
					$dt = new DateTime('@'.$v, new DateTimeZone('UTC'));
					// We have to explicitly specify and then change the time zone because of a
					// DateTime bug: http://bugs.php.net/bug.php?id=43003
					$dt->setTimeZone(new DateTimeZone(date_default_timezone_get()));
				} else {
					$dt = new DateTime($v);
				}
			} catch (Exception $x) {
				throw new PropelException('Error parsing date/time value: ' . var_export($v, true), $x);
			}
		}

		if ( $this->lastlogindate !== null || $dt !== null ) {
			// (nested ifs are a little easier to read in this case)

			$currNorm = ($this->lastlogindate !== null && $tmpDt = new DateTime($this->lastlogindate)) ? $tmpDt->format('Y-m-d H:i:s') : null;
			$newNorm = ($dt !== null) ? $dt->format('Y-m-d H:i:s') : null;

			if ( ($currNorm !== $newNorm) // normalized values don't match 
					)
			{
				$this->lastlogindate = ($dt ? $dt->format('Y-m-d H:i:s') : null);
				$this->modifiedColumns[] = UsersPeer::LASTLOGINDATE;
			}
		} // if either are not null

		return $this;
	} // setLastlogindate()

	/**
	 * Set the value of [clickcounter] column.
	 * 
	 * @param      int $v new value
	 * @return     Users The current object (for fluent API support)
	 */
	public function setClickcounter($v)
	{
		if ($v !== null) {
			$v = (int) $v;
		}

		if ($this->clickcounter !== $v || $v === 0) {
			$this->clickcounter = $v;
			$this->modifiedColumns[] = UsersPeer::CLICKCOUNTER;
		}

		return $this;
	} // setClickcounter()

	/**
	 * Set the value of [ratingcounter] column.
	 * 
	 * @param      int $v new value
	 * @return     Users The current object (for fluent API support)
	 */
	public function setRatingcounter($v)
	{
		if ($v !== null) {
			$v = (int) $v;
		}

		if ($this->ratingcounter !== $v || $v === 0) {
			$this->ratingcounter = $v;
			$this->modifiedColumns[] = UsersPeer::RATINGCOUNTER;
		}

		return $this;
	} // setRatingcounter()

	/**
	 * Set the value of [id_users_permission] column.
	 * 
	 * @param      int $v new value
	 * @return     Users The current object (for fluent API support)
	 */
	public function setIdUsersPermission($v)
	{
		if ($v !== null) {
			$v = (int) $v;
		}

		if ($this->id_users_permission !== $v) {
			$this->id_users_permission = $v;
			$this->modifiedColumns[] = UsersPeer::ID_USERS_PERMISSION;
		}

		if ($this->aUserspermissions !== null && $this->aUserspermissions->getIdUsersPermission() !== $v) {
			$this->aUserspermissions = null;
		}

		return $this;
	} // setIdUsersPermission()

	/**
	 * Set the value of [id_preferences_group] column.
	 * 
	 * @param      int $v new value
	 * @return     Users The current object (for fluent API support)
	 */
	public function setIdPreferencesGroup($v)
	{
		if ($v !== null) {
			$v = (int) $v;
		}

		if ($this->id_preferences_group !== $v) {
			$this->id_preferences_group = $v;
			$this->modifiedColumns[] = UsersPeer::ID_PREFERENCES_GROUP;
		}

		if ($this->aPreferencesgroups !== null && $this->aPreferencesgroups->getIdPreferencesGroup() !== $v) {
			$this->aPreferencesgroups = null;
		}

		return $this;
	} // setIdPreferencesGroup()

	/**
	 * Indicates whether the columns in this object are only set to default values.
	 *
	 * This method can be used in conjunction with isModified() to indicate whether an object is both
	 * modified _and_ has some values set which are non-default.
	 *
	 * @return     boolean Whether the columns in this object are only been set with default values.
	 */
	public function hasOnlyDefaultValues()
	{
			// First, ensure that we don't have any columns that have been modified which aren't default columns.
			if (array_diff($this->modifiedColumns, array(UsersPeer::CLICKCOUNTER,UsersPeer::RATINGCOUNTER))) {
				return false;
			}

			if ($this->clickcounter !== 0) {
				return false;
			}

			if ($this->ratingcounter !== 0) {
				return false;
			}

		// otherwise, everything was equal, so return TRUE
		return true;
	} // hasOnlyDefaultValues()

	/**
	 * Hydrates (populates) the object variables with values from the database resultset.
	 *
	 * An offset (0-based "start column") is specified so that objects can be hydrated
	 * with a subset of the columns in the resultset rows.  This is needed, for example,
	 * for results of JOIN queries where the resultset row includes columns from two or
	 * more tables.
	 *
	 * @param      array $row The row returned by PDOStatement->fetch(PDO::FETCH_NUM)
	 * @param      int $startcol 0-based offset column which indicates which restultset column to start with.
	 * @param      boolean $rehydrate Whether this object is being re-hydrated from the database.
	 * @return     int next starting column
	 * @throws     PropelException  - Any caught Exception will be rewrapped as a PropelException.
	 */
	public function hydrate($row, $startcol = 0, $rehydrate = false)
	{
		try {

			$this->id_user = ($row[$startcol + 0] !== null) ? (int) $row[$startcol + 0] : null;
			$this->login = ($row[$startcol + 1] !== null) ? (string) $row[$startcol + 1] : null;
			$this->password = ($row[$startcol + 2] !== null) ? (string) $row[$startcol + 2] : null;
			$this->avatar = ($row[$startcol + 3] !== null) ? (string) $row[$startcol + 3] : null;
			$this->email = ($row[$startcol + 4] !== null) ? (string) $row[$startcol + 4] : null;
			$this->birthdate = ($row[$startcol + 5] !== null) ? (string) $row[$startcol + 5] : null;
			$this->registerdate = ($row[$startcol + 6] !== null) ? (string) $row[$startcol + 6] : null;
			$this->lastlogindate = ($row[$startcol + 7] !== null) ? (string) $row[$startcol + 7] : null;
			$this->clickcounter = ($row[$startcol + 8] !== null) ? (int) $row[$startcol + 8] : null;
			$this->ratingcounter = ($row[$startcol + 9] !== null) ? (int) $row[$startcol + 9] : null;
			$this->id_users_permission = ($row[$startcol + 10] !== null) ? (int) $row[$startcol + 10] : null;
			$this->id_preferences_group = ($row[$startcol + 11] !== null) ? (int) $row[$startcol + 11] : null;
			$this->resetModified();

			$this->setNew(false);

			if ($rehydrate) {
				$this->ensureConsistency();
			}

			// FIXME - using NUM_COLUMNS may be clearer.
			return $startcol + 12; // 12 = UsersPeer::NUM_COLUMNS - UsersPeer::NUM_LAZY_LOAD_COLUMNS).

		} catch (Exception $e) {
			throw new PropelException("Error populating Users object", $e);
		}
	}

	/**
	 * Checks and repairs the internal consistency of the object.
	 *
	 * This method is executed after an already-instantiated object is re-hydrated
	 * from the database.  It exists to check any foreign keys to make sure that
	 * the objects related to the current object are correct based on foreign key.
	 *
	 * You can override this method in the stub class, but you should always invoke
	 * the base method from the overridden method (i.e. parent::ensureConsistency()),
	 * in case your model changes.
	 *
	 * @throws     PropelException
	 */
	public function ensureConsistency()
	{

		if ($this->aUserspermissions !== null && $this->id_users_permission !== $this->aUserspermissions->getIdUsersPermission()) {
			$this->aUserspermissions = null;
		}
		if ($this->aPreferencesgroups !== null && $this->id_preferences_group !== $this->aPreferencesgroups->getIdPreferencesGroup()) {
			$this->aPreferencesgroups = null;
		}
	} // ensureConsistency

	/**
	 * Reloads this object from datastore based on primary key and (optionally) resets all associated objects.
	 *
	 * This will only work if the object has been saved and has a valid primary key set.
	 *
	 * @param      boolean $deep (optional) Whether to also de-associated any related objects.
	 * @param      PropelPDO $con (optional) The PropelPDO connection to use.
	 * @return     void
	 * @throws     PropelException - if this object is deleted, unsaved or doesn't have pk match in db
	 */
	public function reload($deep = false, PropelPDO $con = null)
	{
		if ($this->isDeleted()) {
			throw new PropelException("Cannot reload a deleted object.");
		}

		if ($this->isNew()) {
			throw new PropelException("Cannot reload an unsaved object.");
		}

		if ($con === null) {
			$con = Propel::getConnection(UsersPeer::DATABASE_NAME, Propel::CONNECTION_READ);
		}

		// We don't need to alter the object instance pool; we're just modifying this instance
		// already in the pool.

		$stmt = UsersPeer::doSelectStmt($this->buildPkeyCriteria(), $con);
		$row = $stmt->fetch(PDO::FETCH_NUM);
		$stmt->closeCursor();
		if (!$row) {
			throw new PropelException('Cannot find matching row in the database to reload object values.');
		}
		$this->hydrate($row, 0, true); // rehydrate

		if ($deep) {  // also de-associate any related objects?

			$this->aUserspermissions = null;
			$this->aPreferencesgroups = null;
			$this->collNewss = null;
			$this->lastNewsCriteria = null;

			$this->singleNewsratingstatistics = null;

			$this->collReviewrequestss = null;
			$this->lastReviewrequestsCriteria = null;

			$this->collUserscategoriesclickss = null;
			$this->lastUserscategoriesclicksCriteria = null;

		} // if (deep)
	}

	/**
	 * Removes this object from datastore and sets delete attribute.
	 *
	 * @param      PropelPDO $con
	 * @return     void
	 * @throws     PropelException
	 * @see        BaseObject::setDeleted()
	 * @see        BaseObject::isDeleted()
	 */
	public function delete(PropelPDO $con = null)
	{
		if ($this->isDeleted()) {
			throw new PropelException("This object has already been deleted.");
		}

		if ($con === null) {
			$con = Propel::getConnection(UsersPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
		}
		
		$con->beginTransaction();
		try {
			UsersPeer::doDelete($this, $con);
			$this->setDeleted(true);
			$con->commit();
		} catch (PropelException $e) {
			$con->rollBack();
			throw $e;
		}
	}

	/**
	 * Persists this object to the database.
	 *
	 * If the object is new, it inserts it; otherwise an update is performed.
	 * All modified related objects will also be persisted in the doSave()
	 * method.  This method wraps all precipitate database operations in a
	 * single transaction.
	 *
	 * @param      PropelPDO $con
	 * @return     int The number of rows affected by this insert/update and any referring fk objects' save() operations.
	 * @throws     PropelException
	 * @see        doSave()
	 */
	public function save(PropelPDO $con = null)
	{
		if ($this->isDeleted()) {
			throw new PropelException("You cannot save an object that has been deleted.");
		}

		if ($con === null) {
			$con = Propel::getConnection(UsersPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
		}
		
		$con->beginTransaction();
		try {
			$affectedRows = $this->doSave($con);
			$con->commit();
			UsersPeer::addInstanceToPool($this);
			return $affectedRows;
		} catch (PropelException $e) {
			$con->rollBack();
			throw $e;
		}
	}

	/**
	 * Performs the work of inserting or updating the row in the database.
	 *
	 * If the object is new, it inserts it; otherwise an update is performed.
	 * All related objects are also updated in this method.
	 *
	 * @param      PropelPDO $con
	 * @return     int The number of rows affected by this insert/update and any referring fk objects' save() operations.
	 * @throws     PropelException
	 * @see        save()
	 */
	protected function doSave(PropelPDO $con)
	{
		$affectedRows = 0; // initialize var to track total num of affected rows
		if (!$this->alreadyInSave) {
			$this->alreadyInSave = true;

			// We call the save method on the following object(s) if they
			// were passed to this object by their coresponding set
			// method.  This object relates to these object(s) by a
			// foreign key reference.

			if ($this->aUserspermissions !== null) {
				if ($this->aUserspermissions->isModified() || $this->aUserspermissions->isNew()) {
					$affectedRows += $this->aUserspermissions->save($con);
				}
				$this->setUserspermissions($this->aUserspermissions);
			}

			if ($this->aPreferencesgroups !== null) {
				if ($this->aPreferencesgroups->isModified() || $this->aPreferencesgroups->isNew()) {
					$affectedRows += $this->aPreferencesgroups->save($con);
				}
				$this->setPreferencesgroups($this->aPreferencesgroups);
			}

			if ($this->isNew() ) {
				$this->modifiedColumns[] = UsersPeer::ID_USER;
			}

			// If this object has been modified, then save it to the database.
			if ($this->isModified()) {
				if ($this->isNew()) {
					$pk = UsersPeer::doInsert($this, $con);
					$affectedRows += 1; // we are assuming that there is only 1 row per doInsert() which
										 // should always be true here (even though technically
										 // BasePeer::doInsert() can insert multiple rows).

					$this->setIdUser($pk);  //[IMV] update autoincrement primary key

					$this->setNew(false);
				} else {
					$affectedRows += UsersPeer::doUpdate($this, $con);
				}

				$this->resetModified(); // [HL] After being saved an object is no longer 'modified'
			}

			if ($this->collNewss !== null) {
				foreach ($this->collNewss as $referrerFK) {
					if (!$referrerFK->isDeleted()) {
						$affectedRows += $referrerFK->save($con);
					}
				}
			}

			if ($this->singleNewsratingstatistics !== null) {
				if (!$this->singleNewsratingstatistics->isDeleted()) {
						$affectedRows += $this->singleNewsratingstatistics->save($con);
				}
			}

			if ($this->collReviewrequestss !== null) {
				foreach ($this->collReviewrequestss as $referrerFK) {
					if (!$referrerFK->isDeleted()) {
						$affectedRows += $referrerFK->save($con);
					}
				}
			}

			if ($this->collUserscategoriesclickss !== null) {
				foreach ($this->collUserscategoriesclickss as $referrerFK) {
					if (!$referrerFK->isDeleted()) {
						$affectedRows += $referrerFK->save($con);
					}
				}
			}

			$this->alreadyInSave = false;

		}
		return $affectedRows;
	} // doSave()

	/**
	 * Array of ValidationFailed objects.
	 * @var        array ValidationFailed[]
	 */
	protected $validationFailures = array();

	/**
	 * Gets any ValidationFailed objects that resulted from last call to validate().
	 *
	 *
	 * @return     array ValidationFailed[]
	 * @see        validate()
	 */
	public function getValidationFailures()
	{
		return $this->validationFailures;
	}

	/**
	 * Validates the objects modified field values and all objects related to this table.
	 *
	 * If $columns is either a column name or an array of column names
	 * only those columns are validated.
	 *
	 * @param      mixed $columns Column name or an array of column names.
	 * @return     boolean Whether all columns pass validation.
	 * @see        doValidate()
	 * @see        getValidationFailures()
	 */
	public function validate($columns = null)
	{
		$res = $this->doValidate($columns);
		if ($res === true) {
			$this->validationFailures = array();
			return true;
		} else {
			$this->validationFailures = $res;
			return false;
		}
	}

	/**
	 * This function performs the validation work for complex object models.
	 *
	 * In addition to checking the current object, all related objects will
	 * also be validated.  If all pass then <code>true</code> is returned; otherwise
	 * an aggreagated array of ValidationFailed objects will be returned.
	 *
	 * @param      array $columns Array of column names to validate.
	 * @return     mixed <code>true</code> if all validations pass; array of <code>ValidationFailed</code> objets otherwise.
	 */
	protected function doValidate($columns = null)
	{
		if (!$this->alreadyInValidation) {
			$this->alreadyInValidation = true;
			$retval = null;

			$failureMap = array();


			// We call the validate method on the following object(s) if they
			// were passed to this object by their coresponding set
			// method.  This object relates to these object(s) by a
			// foreign key reference.

			if ($this->aUserspermissions !== null) {
				if (!$this->aUserspermissions->validate($columns)) {
					$failureMap = array_merge($failureMap, $this->aUserspermissions->getValidationFailures());
				}
			}

			if ($this->aPreferencesgroups !== null) {
				if (!$this->aPreferencesgroups->validate($columns)) {
					$failureMap = array_merge($failureMap, $this->aPreferencesgroups->getValidationFailures());
				}
			}


			if (($retval = UsersPeer::doValidate($this, $columns)) !== true) {
				$failureMap = array_merge($failureMap, $retval);
			}


				if ($this->collNewss !== null) {
					foreach ($this->collNewss as $referrerFK) {
						if (!$referrerFK->validate($columns)) {
							$failureMap = array_merge($failureMap, $referrerFK->getValidationFailures());
						}
					}
				}

				if ($this->singleNewsratingstatistics !== null) {
					if (!$this->singleNewsratingstatistics->validate($columns)) {
						$failureMap = array_merge($failureMap, $this->singleNewsratingstatistics->getValidationFailures());
					}
				}

				if ($this->collReviewrequestss !== null) {
					foreach ($this->collReviewrequestss as $referrerFK) {
						if (!$referrerFK->validate($columns)) {
							$failureMap = array_merge($failureMap, $referrerFK->getValidationFailures());
						}
					}
				}

				if ($this->collUserscategoriesclickss !== null) {
					foreach ($this->collUserscategoriesclickss as $referrerFK) {
						if (!$referrerFK->validate($columns)) {
							$failureMap = array_merge($failureMap, $referrerFK->getValidationFailures());
						}
					}
				}


			$this->alreadyInValidation = false;
		}

		return (!empty($failureMap) ? $failureMap : true);
	}

	/**
	 * Build a Criteria object containing the values of all modified columns in this object.
	 *
	 * @return     Criteria The Criteria object containing all modified values.
	 */
	public function buildCriteria()
	{
		$criteria = new Criteria(UsersPeer::DATABASE_NAME);

		if ($this->isColumnModified(UsersPeer::ID_USER)) $criteria->add(UsersPeer::ID_USER, $this->id_user);
		if ($this->isColumnModified(UsersPeer::LOGIN)) $criteria->add(UsersPeer::LOGIN, $this->login);
		if ($this->isColumnModified(UsersPeer::PASSWORD)) $criteria->add(UsersPeer::PASSWORD, $this->password);
		if ($this->isColumnModified(UsersPeer::AVATAR)) $criteria->add(UsersPeer::AVATAR, $this->avatar);
		if ($this->isColumnModified(UsersPeer::EMAIL)) $criteria->add(UsersPeer::EMAIL, $this->email);
		if ($this->isColumnModified(UsersPeer::BIRTHDATE)) $criteria->add(UsersPeer::BIRTHDATE, $this->birthdate);
		if ($this->isColumnModified(UsersPeer::REGISTERDATE)) $criteria->add(UsersPeer::REGISTERDATE, $this->registerdate);
		if ($this->isColumnModified(UsersPeer::LASTLOGINDATE)) $criteria->add(UsersPeer::LASTLOGINDATE, $this->lastlogindate);
		if ($this->isColumnModified(UsersPeer::CLICKCOUNTER)) $criteria->add(UsersPeer::CLICKCOUNTER, $this->clickcounter);
		if ($this->isColumnModified(UsersPeer::RATINGCOUNTER)) $criteria->add(UsersPeer::RATINGCOUNTER, $this->ratingcounter);
		if ($this->isColumnModified(UsersPeer::ID_USERS_PERMISSION)) $criteria->add(UsersPeer::ID_USERS_PERMISSION, $this->id_users_permission);
		if ($this->isColumnModified(UsersPeer::ID_PREFERENCES_GROUP)) $criteria->add(UsersPeer::ID_PREFERENCES_GROUP, $this->id_preferences_group);

		return $criteria;
	}

	/**
	 * Builds a Criteria object containing the primary key for this object.
	 *
	 * Unlike buildCriteria() this method includes the primary key values regardless
	 * of whether or not they have been modified.
	 *
	 * @return     Criteria The Criteria object containing value(s) for primary key(s).
	 */
	public function buildPkeyCriteria()
	{
		$criteria = new Criteria(UsersPeer::DATABASE_NAME);

		$criteria->add(UsersPeer::ID_USER, $this->id_user);

		return $criteria;
	}

	/**
	 * Returns the primary key for this object (row).
	 * @return     int
	 */
	public function getPrimaryKey()
	{
		return $this->getIdUser();
	}

	/**
	 * Generic method to set the primary key (id_user column).
	 *
	 * @param      int $key Primary key.
	 * @return     void
	 */
	public function setPrimaryKey($key)
	{
		$this->setIdUser($key);
	}

	/**
	 * Sets contents of passed object to values from current object.
	 *
	 * If desired, this method can also make copies of all associated (fkey referrers)
	 * objects.
	 *
	 * @param      object $copyObj An object of Users (or compatible) type.
	 * @param      boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row.
	 * @throws     PropelException
	 */
	public function copyInto($copyObj, $deepCopy = false)
	{

		$copyObj->setLogin($this->login);

		$copyObj->setPassword($this->password);

		$copyObj->setAvatar($this->avatar);

		$copyObj->setEmail($this->email);

		$copyObj->setBirthdate($this->birthdate);

		$copyObj->setRegisterdate($this->registerdate);

		$copyObj->setLastlogindate($this->lastlogindate);

		$copyObj->setClickcounter($this->clickcounter);

		$copyObj->setRatingcounter($this->ratingcounter);

		$copyObj->setIdUsersPermission($this->id_users_permission);

		$copyObj->setIdPreferencesGroup($this->id_preferences_group);


		if ($deepCopy) {
			// important: temporarily setNew(false) because this affects the behavior of
			// the getter/setter methods for fkey referrer objects.
			$copyObj->setNew(false);

			foreach ($this->getNewss() as $relObj) {
				if ($relObj !== $this) {  // ensure that we don't try to copy a reference to ourselves
					$copyObj->addNews($relObj->copy($deepCopy));
				}
			}

			$relObj = $this->getNewsratingstatistics();
			if ($relObj) {
				$copyObj->setNewsratingstatistics($relObj->copy($deepCopy));
			}

			foreach ($this->getReviewrequestss() as $relObj) {
				if ($relObj !== $this) {  // ensure that we don't try to copy a reference to ourselves
					$copyObj->addReviewrequests($relObj->copy($deepCopy));
				}
			}

			foreach ($this->getUserscategoriesclickss() as $relObj) {
				if ($relObj !== $this) {  // ensure that we don't try to copy a reference to ourselves
					$copyObj->addUserscategoriesclicks($relObj->copy($deepCopy));
				}
			}

		} // if ($deepCopy)


		$copyObj->setNew(true);

		$copyObj->setIdUser(NULL); // this is a auto-increment column, so set to default value

	}

	/**
	 * Makes a copy of this object that will be inserted as a new row in table when saved.
	 * It creates a new object filling in the simple attributes, but skipping any primary
	 * keys that are defined for the table.
	 *
	 * If desired, this method can also make copies of all associated (fkey referrers)
	 * objects.
	 *
	 * @param      boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row.
	 * @return     Users Clone of current object.
	 * @throws     PropelException
	 */
	public function copy($deepCopy = false)
	{
		// we use get_class(), because this might be a subclass
		$clazz = get_class($this);
		$copyObj = new $clazz();
		$this->copyInto($copyObj, $deepCopy);
		return $copyObj;
	}

	/**
	 * Returns a peer instance associated with this om.
	 *
	 * Since Peer classes are not to have any instance attributes, this method returns the
	 * same instance for all member of this class. The method could therefore
	 * be static, but this would prevent one from overriding the behavior.
	 *
	 * @return     UsersPeer
	 */
	public function getPeer()
	{
		if (self::$peer === null) {
			self::$peer = new UsersPeer();
		}
		return self::$peer;
	}

	/**
	 * Declares an association between this object and a Userspermissions object.
	 *
	 * @param      Userspermissions $v
	 * @return     Users The current object (for fluent API support)
	 * @throws     PropelException
	 */
	public function setUserspermissions(Userspermissions $v = null)
	{
		if ($v === null) {
			$this->setIdUsersPermission(NULL);
		} else {
			$this->setIdUsersPermission($v->getIdUsersPermission());
		}

		$this->aUserspermissions = $v;

		// Add binding for other direction of this n:n relationship.
		// If this object has already been added to the Userspermissions object, it will not be re-added.
		if ($v !== null) {
			$v->addUsers($this);
		}

		return $this;
	}


	/**
	 * Get the associated Userspermissions object
	 *
	 * @param      PropelPDO Optional Connection object.
	 * @return     Userspermissions The associated Userspermissions object.
	 * @throws     PropelException
	 */
	public function getUserspermissions(PropelPDO $con = null)
	{
		if ($this->aUserspermissions === null && ($this->id_users_permission !== null)) {
			$this->aUserspermissions = UserspermissionsPeer::retrieveByPK($this->id_users_permission, $con);
			/* The following can be used additionally to
			   guarantee the related object contains a reference
			   to this object.  This level of coupling may, however, be
			   undesirable since it could result in an only partially populated collection
			   in the referenced object.
			   $this->aUserspermissions->addUserss($this);
			 */
		}
		return $this->aUserspermissions;
	}

	/**
	 * Declares an association between this object and a Preferencesgroups object.
	 *
	 * @param      Preferencesgroups $v
	 * @return     Users The current object (for fluent API support)
	 * @throws     PropelException
	 */
	public function setPreferencesgroups(Preferencesgroups $v = null)
	{
		if ($v === null) {
			$this->setIdPreferencesGroup(NULL);
		} else {
			$this->setIdPreferencesGroup($v->getIdPreferencesGroup());
		}

		$this->aPreferencesgroups = $v;

		// Add binding for other direction of this n:n relationship.
		// If this object has already been added to the Preferencesgroups object, it will not be re-added.
		if ($v !== null) {
			$v->addUsers($this);
		}

		return $this;
	}


	/**
	 * Get the associated Preferencesgroups object
	 *
	 * @param      PropelPDO Optional Connection object.
	 * @return     Preferencesgroups The associated Preferencesgroups object.
	 * @throws     PropelException
	 */
	public function getPreferencesgroups(PropelPDO $con = null)
	{
		if ($this->aPreferencesgroups === null && ($this->id_preferences_group !== null)) {
			$this->aPreferencesgroups = PreferencesgroupsPeer::retrieveByPK($this->id_preferences_group, $con);
			/* The following can be used additionally to
			   guarantee the related object contains a reference
			   to this object.  This level of coupling may, however, be
			   undesirable since it could result in an only partially populated collection
			   in the referenced object.
			   $this->aPreferencesgroups->addUserss($this);
			 */
		}
		return $this->aPreferencesgroups;
	}

	/**
	 * Clears out the collNewss collection (array).
	 *
	 * This does not modify the database; however, it will remove any associated objects, causing
	 * them to be refetched by subsequent calls to accessor method.
	 *
	 * @return     void
	 * @see        addNewss()
	 */
	public function clearNewss()
	{
		$this->collNewss = null; // important to set this to NULL since that means it is uninitialized
	}

	/**
	 * Initializes the collNewss collection (array).
	 *
	 * By default this just sets the collNewss collection to an empty array (like clearcollNewss());
	 * however, you may wish to override this method in your stub class to provide setting appropriate
	 * to your application -- for example, setting the initial array to the values stored in database.
	 *
	 * @return     void
	 */
	public function initNewss()
	{
		$this->collNewss = array();
	}

	/**
	 * Gets an array of News objects which contain a foreign key that references this object.
	 *
	 * If this collection has already been initialized with an identical Criteria, it returns the collection.
	 * Otherwise if this Users has previously been saved, it will retrieve
	 * related Newss from storage. If this Users is new, it will return
	 * an empty collection or the current collection, the criteria is ignored on a new object.
	 *
	 * @param      PropelPDO $con
	 * @param      Criteria $criteria
	 * @return     array News[]
	 * @throws     PropelException
	 */
	public function getNewss($criteria = null, PropelPDO $con = null)
	{
		if ($criteria === null) {
			$criteria = new Criteria(UsersPeer::DATABASE_NAME);
		}
		elseif ($criteria instanceof Criteria)
		{
			$criteria = clone $criteria;
		}

		if ($this->collNewss === null) {
			if ($this->isNew()) {
			   $this->collNewss = array();
			} else {

				$criteria->add(NewsPeer::ID_USER, $this->id_user);

				NewsPeer::addSelectColumns($criteria);
				$this->collNewss = NewsPeer::doSelect($criteria, $con);
			}
		} else {
			// criteria has no effect for a new object
			if (!$this->isNew()) {
				// the following code is to determine if a new query is
				// called for.  If the criteria is the same as the last
				// one, just return the collection.


				$criteria->add(NewsPeer::ID_USER, $this->id_user);

				NewsPeer::addSelectColumns($criteria);
				if (!isset($this->lastNewsCriteria) || !$this->lastNewsCriteria->equals($criteria)) {
					$this->collNewss = NewsPeer::doSelect($criteria, $con);
				}
			}
		}
		$this->lastNewsCriteria = $criteria;
		return $this->collNewss;
	}

	/**
	 * Returns the number of related News objects.
	 *
	 * @param      Criteria $criteria
	 * @param      boolean $distinct
	 * @param      PropelPDO $con
	 * @return     int Count of related News objects.
	 * @throws     PropelException
	 */
	public function countNewss(Criteria $criteria = null, $distinct = false, PropelPDO $con = null)
	{
		if ($criteria === null) {
			$criteria = new Criteria(UsersPeer::DATABASE_NAME);
		} else {
			$criteria = clone $criteria;
		}

		if ($distinct) {
			$criteria->setDistinct();
		}

		$count = null;

		if ($this->collNewss === null) {
			if ($this->isNew()) {
				$count = 0;
			} else {

				$criteria->add(NewsPeer::ID_USER, $this->id_user);

				$count = NewsPeer::doCount($criteria, $con);
			}
		} else {
			// criteria has no effect for a new object
			if (!$this->isNew()) {
				// the following code is to determine if a new query is
				// called for.  If the criteria is the same as the last
				// one, just return count of the collection.


				$criteria->add(NewsPeer::ID_USER, $this->id_user);

				if (!isset($this->lastNewsCriteria) || !$this->lastNewsCriteria->equals($criteria)) {
					$count = NewsPeer::doCount($criteria, $con);
				} else {
					$count = count($this->collNewss);
				}
			} else {
				$count = count($this->collNewss);
			}
		}
		$this->lastNewsCriteria = $criteria;
		return $count;
	}

	/**
	 * Method called to associate a News object to this object
	 * through the News foreign key attribute.
	 *
	 * @param      News $l News
	 * @return     void
	 * @throws     PropelException
	 */
	public function addNews(News $l)
	{
		if ($this->collNewss === null) {
			$this->initNewss();
		}
		if (!in_array($l, $this->collNewss, true)) { // only add it if the **same** object is not already associated
			array_push($this->collNewss, $l);
			$l->setUsers($this);
		}
	}


	/**
	 * If this collection has already been initialized with
	 * an identical criteria, it returns the collection.
	 * Otherwise if this Users is new, it will return
	 * an empty collection; or if this Users has previously
	 * been saved, it will retrieve related Newss from storage.
	 *
	 * This method is protected by default in order to keep the public
	 * api reasonable.  You can provide public methods for those you
	 * actually need in Users.
	 */
	public function getNewssJoinVortals($criteria = null, $con = null, $join_behavior = Criteria::LEFT_JOIN)
	{
		if ($criteria === null) {
			$criteria = new Criteria(UsersPeer::DATABASE_NAME);
		}
		elseif ($criteria instanceof Criteria)
		{
			$criteria = clone $criteria;
		}

		if ($this->collNewss === null) {
			if ($this->isNew()) {
				$this->collNewss = array();
			} else {

				$criteria->add(NewsPeer::ID_USER, $this->id_user);

				$this->collNewss = NewsPeer::doSelectJoinVortals($criteria, $con, $join_behavior);
			}
		} else {
			// the following code is to determine if a new query is
			// called for.  If the criteria is the same as the last
			// one, just return the collection.

			$criteria->add(NewsPeer::ID_USER, $this->id_user);

			if (!isset($this->lastNewsCriteria) || !$this->lastNewsCriteria->equals($criteria)) {
				$this->collNewss = NewsPeer::doSelectJoinVortals($criteria, $con, $join_behavior);
			}
		}
		$this->lastNewsCriteria = $criteria;

		return $this->collNewss;
	}


	/**
	 * If this collection has already been initialized with
	 * an identical criteria, it returns the collection.
	 * Otherwise if this Users is new, it will return
	 * an empty collection; or if this Users has previously
	 * been saved, it will retrieve related Newss from storage.
	 *
	 * This method is protected by default in order to keep the public
	 * api reasonable.  You can provide public methods for those you
	 * actually need in Users.
	 */
	public function getNewssJoinCategories($criteria = null, $con = null, $join_behavior = Criteria::LEFT_JOIN)
	{
		if ($criteria === null) {
			$criteria = new Criteria(UsersPeer::DATABASE_NAME);
		}
		elseif ($criteria instanceof Criteria)
		{
			$criteria = clone $criteria;
		}

		if ($this->collNewss === null) {
			if ($this->isNew()) {
				$this->collNewss = array();
			} else {

				$criteria->add(NewsPeer::ID_USER, $this->id_user);

				$this->collNewss = NewsPeer::doSelectJoinCategories($criteria, $con, $join_behavior);
			}
		} else {
			// the following code is to determine if a new query is
			// called for.  If the criteria is the same as the last
			// one, just return the collection.

			$criteria->add(NewsPeer::ID_USER, $this->id_user);

			if (!isset($this->lastNewsCriteria) || !$this->lastNewsCriteria->equals($criteria)) {
				$this->collNewss = NewsPeer::doSelectJoinCategories($criteria, $con, $join_behavior);
			}
		}
		$this->lastNewsCriteria = $criteria;

		return $this->collNewss;
	}


	/**
	 * If this collection has already been initialized with
	 * an identical criteria, it returns the collection.
	 * Otherwise if this Users is new, it will return
	 * an empty collection; or if this Users has previously
	 * been saved, it will retrieve related Newss from storage.
	 *
	 * This method is protected by default in order to keep the public
	 * api reasonable.  You can provide public methods for those you
	 * actually need in Users.
	 */
	public function getNewssJoinRequeststatuses($criteria = null, $con = null, $join_behavior = Criteria::LEFT_JOIN)
	{
		if ($criteria === null) {
			$criteria = new Criteria(UsersPeer::DATABASE_NAME);
		}
		elseif ($criteria instanceof Criteria)
		{
			$criteria = clone $criteria;
		}

		if ($this->collNewss === null) {
			if ($this->isNew()) {
				$this->collNewss = array();
			} else {

				$criteria->add(NewsPeer::ID_USER, $this->id_user);

				$this->collNewss = NewsPeer::doSelectJoinRequeststatuses($criteria, $con, $join_behavior);
			}
		} else {
			// the following code is to determine if a new query is
			// called for.  If the criteria is the same as the last
			// one, just return the collection.

			$criteria->add(NewsPeer::ID_USER, $this->id_user);

			if (!isset($this->lastNewsCriteria) || !$this->lastNewsCriteria->equals($criteria)) {
				$this->collNewss = NewsPeer::doSelectJoinRequeststatuses($criteria, $con, $join_behavior);
			}
		}
		$this->lastNewsCriteria = $criteria;

		return $this->collNewss;
	}

	/**
	 * Gets a single Newsratingstatistics object, which is related to this object by a one-to-one relationship.
	 *
	 * @param      PropelPDO $con
	 * @return     Newsratingstatistics
	 * @throws     PropelException
	 */
	public function getNewsratingstatistics(PropelPDO $con = null)
	{

		if ($this->singleNewsratingstatistics === null && !$this->isNew()) {
			$this->singleNewsratingstatistics = NewsratingstatisticsPeer::retrieveByPK($this->id_user, $con);
		}

		return $this->singleNewsratingstatistics;
	}

	/**
	 * Sets a single Newsratingstatistics object as related to this object by a one-to-one relationship.
	 *
	 * @param      Newsratingstatistics $l Newsratingstatistics
	 * @return     Users The current object (for fluent API support)
	 * @throws     PropelException
	 */
	public function setNewsratingstatistics(Newsratingstatistics $v)
	{
		$this->singleNewsratingstatistics = $v;

		// Make sure that that the passed-in Newsratingstatistics isn't already associated with this object
		if ($v->getUsers() === null) {
			$v->setUsers($this);
		}

		return $this;
	}

	/**
	 * Clears out the collReviewrequestss collection (array).
	 *
	 * This does not modify the database; however, it will remove any associated objects, causing
	 * them to be refetched by subsequent calls to accessor method.
	 *
	 * @return     void
	 * @see        addReviewrequestss()
	 */
	public function clearReviewrequestss()
	{
		$this->collReviewrequestss = null; // important to set this to NULL since that means it is uninitialized
	}

	/**
	 * Initializes the collReviewrequestss collection (array).
	 *
	 * By default this just sets the collReviewrequestss collection to an empty array (like clearcollReviewrequestss());
	 * however, you may wish to override this method in your stub class to provide setting appropriate
	 * to your application -- for example, setting the initial array to the values stored in database.
	 *
	 * @return     void
	 */
	public function initReviewrequestss()
	{
		$this->collReviewrequestss = array();
	}

	/**
	 * Gets an array of Reviewrequests objects which contain a foreign key that references this object.
	 *
	 * If this collection has already been initialized with an identical Criteria, it returns the collection.
	 * Otherwise if this Users has previously been saved, it will retrieve
	 * related Reviewrequestss from storage. If this Users is new, it will return
	 * an empty collection or the current collection, the criteria is ignored on a new object.
	 *
	 * @param      PropelPDO $con
	 * @param      Criteria $criteria
	 * @return     array Reviewrequests[]
	 * @throws     PropelException
	 */
	public function getReviewrequestss($criteria = null, PropelPDO $con = null)
	{
		if ($criteria === null) {
			$criteria = new Criteria(UsersPeer::DATABASE_NAME);
		}
		elseif ($criteria instanceof Criteria)
		{
			$criteria = clone $criteria;
		}

		if ($this->collReviewrequestss === null) {
			if ($this->isNew()) {
			   $this->collReviewrequestss = array();
			} else {

				$criteria->add(ReviewrequestsPeer::ID_USER, $this->id_user);

				ReviewrequestsPeer::addSelectColumns($criteria);
				$this->collReviewrequestss = ReviewrequestsPeer::doSelect($criteria, $con);
			}
		} else {
			// criteria has no effect for a new object
			if (!$this->isNew()) {
				// the following code is to determine if a new query is
				// called for.  If the criteria is the same as the last
				// one, just return the collection.


				$criteria->add(ReviewrequestsPeer::ID_USER, $this->id_user);

				ReviewrequestsPeer::addSelectColumns($criteria);
				if (!isset($this->lastReviewrequestsCriteria) || !$this->lastReviewrequestsCriteria->equals($criteria)) {
					$this->collReviewrequestss = ReviewrequestsPeer::doSelect($criteria, $con);
				}
			}
		}
		$this->lastReviewrequestsCriteria = $criteria;
		return $this->collReviewrequestss;
	}

	/**
	 * Returns the number of related Reviewrequests objects.
	 *
	 * @param      Criteria $criteria
	 * @param      boolean $distinct
	 * @param      PropelPDO $con
	 * @return     int Count of related Reviewrequests objects.
	 * @throws     PropelException
	 */
	public function countReviewrequestss(Criteria $criteria = null, $distinct = false, PropelPDO $con = null)
	{
		if ($criteria === null) {
			$criteria = new Criteria(UsersPeer::DATABASE_NAME);
		} else {
			$criteria = clone $criteria;
		}

		if ($distinct) {
			$criteria->setDistinct();
		}

		$count = null;

		if ($this->collReviewrequestss === null) {
			if ($this->isNew()) {
				$count = 0;
			} else {

				$criteria->add(ReviewrequestsPeer::ID_USER, $this->id_user);

				$count = ReviewrequestsPeer::doCount($criteria, $con);
			}
		} else {
			// criteria has no effect for a new object
			if (!$this->isNew()) {
				// the following code is to determine if a new query is
				// called for.  If the criteria is the same as the last
				// one, just return count of the collection.


				$criteria->add(ReviewrequestsPeer::ID_USER, $this->id_user);

				if (!isset($this->lastReviewrequestsCriteria) || !$this->lastReviewrequestsCriteria->equals($criteria)) {
					$count = ReviewrequestsPeer::doCount($criteria, $con);
				} else {
					$count = count($this->collReviewrequestss);
				}
			} else {
				$count = count($this->collReviewrequestss);
			}
		}
		$this->lastReviewrequestsCriteria = $criteria;
		return $count;
	}

	/**
	 * Method called to associate a Reviewrequests object to this object
	 * through the Reviewrequests foreign key attribute.
	 *
	 * @param      Reviewrequests $l Reviewrequests
	 * @return     void
	 * @throws     PropelException
	 */
	public function addReviewrequests(Reviewrequests $l)
	{
		if ($this->collReviewrequestss === null) {
			$this->initReviewrequestss();
		}
		if (!in_array($l, $this->collReviewrequestss, true)) { // only add it if the **same** object is not already associated
			array_push($this->collReviewrequestss, $l);
			$l->setUsers($this);
		}
	}


	/**
	 * If this collection has already been initialized with
	 * an identical criteria, it returns the collection.
	 * Otherwise if this Users is new, it will return
	 * an empty collection; or if this Users has previously
	 * been saved, it will retrieve related Reviewrequestss from storage.
	 *
	 * This method is protected by default in order to keep the public
	 * api reasonable.  You can provide public methods for those you
	 * actually need in Users.
	 */
	public function getReviewrequestssJoinRequeststatuses($criteria = null, $con = null, $join_behavior = Criteria::LEFT_JOIN)
	{
		if ($criteria === null) {
			$criteria = new Criteria(UsersPeer::DATABASE_NAME);
		}
		elseif ($criteria instanceof Criteria)
		{
			$criteria = clone $criteria;
		}

		if ($this->collReviewrequestss === null) {
			if ($this->isNew()) {
				$this->collReviewrequestss = array();
			} else {

				$criteria->add(ReviewrequestsPeer::ID_USER, $this->id_user);

				$this->collReviewrequestss = ReviewrequestsPeer::doSelectJoinRequeststatuses($criteria, $con, $join_behavior);
			}
		} else {
			// the following code is to determine if a new query is
			// called for.  If the criteria is the same as the last
			// one, just return the collection.

			$criteria->add(ReviewrequestsPeer::ID_USER, $this->id_user);

			if (!isset($this->lastReviewrequestsCriteria) || !$this->lastReviewrequestsCriteria->equals($criteria)) {
				$this->collReviewrequestss = ReviewrequestsPeer::doSelectJoinRequeststatuses($criteria, $con, $join_behavior);
			}
		}
		$this->lastReviewrequestsCriteria = $criteria;

		return $this->collReviewrequestss;
	}

	/**
	 * Clears out the collUserscategoriesclickss collection (array).
	 *
	 * This does not modify the database; however, it will remove any associated objects, causing
	 * them to be refetched by subsequent calls to accessor method.
	 *
	 * @return     void
	 * @see        addUserscategoriesclickss()
	 */
	public function clearUserscategoriesclickss()
	{
		$this->collUserscategoriesclickss = null; // important to set this to NULL since that means it is uninitialized
	}

	/**
	 * Initializes the collUserscategoriesclickss collection (array).
	 *
	 * By default this just sets the collUserscategoriesclickss collection to an empty array (like clearcollUserscategoriesclickss());
	 * however, you may wish to override this method in your stub class to provide setting appropriate
	 * to your application -- for example, setting the initial array to the values stored in database.
	 *
	 * @return     void
	 */
	public function initUserscategoriesclickss()
	{
		$this->collUserscategoriesclickss = array();
	}

	/**
	 * Gets an array of Userscategoriesclicks objects which contain a foreign key that references this object.
	 *
	 * If this collection has already been initialized with an identical Criteria, it returns the collection.
	 * Otherwise if this Users has previously been saved, it will retrieve
	 * related Userscategoriesclickss from storage. If this Users is new, it will return
	 * an empty collection or the current collection, the criteria is ignored on a new object.
	 *
	 * @param      PropelPDO $con
	 * @param      Criteria $criteria
	 * @return     array Userscategoriesclicks[]
	 * @throws     PropelException
	 */
	public function getUserscategoriesclickss($criteria = null, PropelPDO $con = null)
	{
		if ($criteria === null) {
			$criteria = new Criteria(UsersPeer::DATABASE_NAME);
		}
		elseif ($criteria instanceof Criteria)
		{
			$criteria = clone $criteria;
		}

		if ($this->collUserscategoriesclickss === null) {
			if ($this->isNew()) {
			   $this->collUserscategoriesclickss = array();
			} else {

				$criteria->add(UserscategoriesclicksPeer::ID_USER, $this->id_user);

				UserscategoriesclicksPeer::addSelectColumns($criteria);
				$this->collUserscategoriesclickss = UserscategoriesclicksPeer::doSelect($criteria, $con);
			}
		} else {
			// criteria has no effect for a new object
			if (!$this->isNew()) {
				// the following code is to determine if a new query is
				// called for.  If the criteria is the same as the last
				// one, just return the collection.


				$criteria->add(UserscategoriesclicksPeer::ID_USER, $this->id_user);

				UserscategoriesclicksPeer::addSelectColumns($criteria);
				if (!isset($this->lastUserscategoriesclicksCriteria) || !$this->lastUserscategoriesclicksCriteria->equals($criteria)) {
					$this->collUserscategoriesclickss = UserscategoriesclicksPeer::doSelect($criteria, $con);
				}
			}
		}
		$this->lastUserscategoriesclicksCriteria = $criteria;
		return $this->collUserscategoriesclickss;
	}

	/**
	 * Returns the number of related Userscategoriesclicks objects.
	 *
	 * @param      Criteria $criteria
	 * @param      boolean $distinct
	 * @param      PropelPDO $con
	 * @return     int Count of related Userscategoriesclicks objects.
	 * @throws     PropelException
	 */
	public function countUserscategoriesclickss(Criteria $criteria = null, $distinct = false, PropelPDO $con = null)
	{
		if ($criteria === null) {
			$criteria = new Criteria(UsersPeer::DATABASE_NAME);
		} else {
			$criteria = clone $criteria;
		}

		if ($distinct) {
			$criteria->setDistinct();
		}

		$count = null;

		if ($this->collUserscategoriesclickss === null) {
			if ($this->isNew()) {
				$count = 0;
			} else {

				$criteria->add(UserscategoriesclicksPeer::ID_USER, $this->id_user);

				$count = UserscategoriesclicksPeer::doCount($criteria, $con);
			}
		} else {
			// criteria has no effect for a new object
			if (!$this->isNew()) {
				// the following code is to determine if a new query is
				// called for.  If the criteria is the same as the last
				// one, just return count of the collection.


				$criteria->add(UserscategoriesclicksPeer::ID_USER, $this->id_user);

				if (!isset($this->lastUserscategoriesclicksCriteria) || !$this->lastUserscategoriesclicksCriteria->equals($criteria)) {
					$count = UserscategoriesclicksPeer::doCount($criteria, $con);
				} else {
					$count = count($this->collUserscategoriesclickss);
				}
			} else {
				$count = count($this->collUserscategoriesclickss);
			}
		}
		$this->lastUserscategoriesclicksCriteria = $criteria;
		return $count;
	}

	/**
	 * Method called to associate a Userscategoriesclicks object to this object
	 * through the Userscategoriesclicks foreign key attribute.
	 *
	 * @param      Userscategoriesclicks $l Userscategoriesclicks
	 * @return     void
	 * @throws     PropelException
	 */
	public function addUserscategoriesclicks(Userscategoriesclicks $l)
	{
		if ($this->collUserscategoriesclickss === null) {
			$this->initUserscategoriesclickss();
		}
		if (!in_array($l, $this->collUserscategoriesclickss, true)) { // only add it if the **same** object is not already associated
			array_push($this->collUserscategoriesclickss, $l);
			$l->setUsers($this);
		}
	}


	/**
	 * If this collection has already been initialized with
	 * an identical criteria, it returns the collection.
	 * Otherwise if this Users is new, it will return
	 * an empty collection; or if this Users has previously
	 * been saved, it will retrieve related Userscategoriesclickss from storage.
	 *
	 * This method is protected by default in order to keep the public
	 * api reasonable.  You can provide public methods for those you
	 * actually need in Users.
	 */
	public function getUserscategoriesclickssJoinCategories($criteria = null, $con = null, $join_behavior = Criteria::LEFT_JOIN)
	{
		if ($criteria === null) {
			$criteria = new Criteria(UsersPeer::DATABASE_NAME);
		}
		elseif ($criteria instanceof Criteria)
		{
			$criteria = clone $criteria;
		}

		if ($this->collUserscategoriesclickss === null) {
			if ($this->isNew()) {
				$this->collUserscategoriesclickss = array();
			} else {

				$criteria->add(UserscategoriesclicksPeer::ID_USER, $this->id_user);

				$this->collUserscategoriesclickss = UserscategoriesclicksPeer::doSelectJoinCategories($criteria, $con, $join_behavior);
			}
		} else {
			// the following code is to determine if a new query is
			// called for.  If the criteria is the same as the last
			// one, just return the collection.

			$criteria->add(UserscategoriesclicksPeer::ID_USER, $this->id_user);

			if (!isset($this->lastUserscategoriesclicksCriteria) || !$this->lastUserscategoriesclicksCriteria->equals($criteria)) {
				$this->collUserscategoriesclickss = UserscategoriesclicksPeer::doSelectJoinCategories($criteria, $con, $join_behavior);
			}
		}
		$this->lastUserscategoriesclicksCriteria = $criteria;

		return $this->collUserscategoriesclickss;
	}

	/**
	 * Resets all collections of referencing foreign keys.
	 *
	 * This method is a user-space workaround for PHP's inability to garbage collect objects
	 * with circular references.  This is currently necessary when using Propel in certain
	 * daemon or large-volumne/high-memory operations.
	 *
	 * @param      boolean $deep Whether to also clear the references on all associated objects.
	 */
	public function clearAllReferences($deep = false)
	{
		if ($deep) {
			if ($this->collNewss) {
				foreach ((array) $this->collNewss as $o) {
					$o->clearAllReferences($deep);
				}
			}
			if ($this->singleNewsratingstatistics) {
				$this->singleNewsratingstatistics->clearAllReferences($deep);
			}
			if ($this->collReviewrequestss) {
				foreach ((array) $this->collReviewrequestss as $o) {
					$o->clearAllReferences($deep);
				}
			}
			if ($this->collUserscategoriesclickss) {
				foreach ((array) $this->collUserscategoriesclickss as $o) {
					$o->clearAllReferences($deep);
				}
			}
		} // if ($deep)

		$this->collNewss = null;
		$this->singleNewsratingstatistics = null;
		$this->collReviewrequestss = null;
		$this->collUserscategoriesclickss = null;
			$this->aUserspermissions = null;
			$this->aPreferencesgroups = null;
	}

} // BaseUsers
